# _*_ coding : utf-8 _*_
# @Time : 2024-05-29 11:02
# @Author : haowen
# @File : 5.人脸检测
# @Project : face identifying
import cv2 as cv
# 检测函数
def face_detect_method():
    gray = cv.cvtColor(img,cv.COLOR_BGR2RGB)
    face_detect = cv.CascadeClassifier("D:/opencv/opencv/sources/data/haarcascades/haarcascade_frontalface_alt2.xml")
    face = face_detect.detectMultiScale(gray,1.01,5)
    for x,y,w,h in face:
        cv.rectangle(img,(x,y),(x+w,y+h),color=(0,0,255),thickness=2)

    cv.imshow("result",img)

img = cv.imread("image/1.JPG")
face_detect_method()

while True:
    if ord('q') == cv.waitKey(0):
        break

cv.destroyAllWindows()